var fs = require('fs'),
	webapp = require('./web/webapp'),
	log = require('./core/log.js'),
	controller = require('./core/controller.js');

String.prototype.endsWith = function(suffix) {
	return this.indexOf(suffix, this.length - suffix.length) !== -1;
};

// TODO start core modules here

// Starting all sources !
fs.readdirSync('./sources').forEach(function(file) {
	if (file.endsWith('.js')) {
		require('./sources/' + file).startListen();
		log.info('init', 'launching ' + file + '...');
	}
});

controller.launchAllModules();

webapp.start();


